package cn.lds.j368.dsedu.service.impl;

import cn.lds.j368.dsedu.constent.DseduConstent;
import cn.lds.j368.dsedu.dto.ResultJson;
import cn.lds.j368.dsedu.entity.Order;
import cn.lds.j368.dsedu.exceipeion.SysException;
import cn.lds.j368.dsedu.mapper.OrderMapper;
import cn.lds.j368.dsedu.service.OrderSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderSerivce {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public ResultJson<List<Order>> selectOrderAll() throws SysException {

        List<Order> orders = orderMapper.selectList(null);

        if (CollectionUtils.isEmpty(orders)){
            throw new SysException(DseduConstent.DseduCommonMsg.SYS_FIND_DATA_FAIL);
        }

        return ResultJson.bulidSuccess(orders);
    }

    @Override
    public ResultJson addOrder(Order order) throws SysException {

        int insert = orderMapper.insert(order);

        if(insert <=0){
            throw new SysException(DseduConstent.DseduCommonMsg.SYS_ADD_DATA_FAIL);
        }

        return ResultJson.bulidSuccess(null);
    }
}
